package oaSystem.web.controller.rest;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import oaSystem.entity.Employee;
import oaSystem.entity.Message;
import oaSystem.mapper.MessageMapper;

@Controller
@RequestMapping("/rest")
@RestController
public class Rest_MessageController {
	@Autowired
	private MessageMapper messageMapper;
	
	/**
	 * 增加收件人
	 * @param session
	 * @param receiver_id
	 */
	@RequestMapping(value="/receiver-add",method=RequestMethod.GET)
	public void receiver_id(HttpSession session,Integer receiver_id){
		@SuppressWarnings("unchecked")
		List<Employee> receiverList = (List<Employee>)session.getAttribute("receiverList");
		if(receiverList==null){
			receiverList=new ArrayList<Employee>();
		}
		Employee e = new Employee(receiver_id);
		receiverList.add(e);
		session.setAttribute("receiverList", receiverList);
	}
	
	/**
	 * 邮件编辑
	 * @param messageId
	 * @return
	 */
	@RequestMapping(value="/message-edit",method=RequestMethod.GET)
	public Message fetchOne(Integer messageId){
		return messageMapper.fetchMessageById(messageId);
	}
}
